package com.wbihua.common.metrics.interceptor;

import com.wbihua.common.metrics.manager.MetricManager;
import com.wbihua.common.metrics.metric.impl.EventCounter;
import com.wbihua.common.metrics.metric.impl.EventGauge;
import com.wbihua.common.metrics.metric.impl.EventSummary;
import com.wbihua.common.metrics.metric.impl.EventTimer;
import com.wbihua.common.metrics.type.*;
import com.wbihua.metrics.metric.PrometheusMetricCounter;
import com.wbihua.metrics.metric.PrometheusMetricGauge;
import com.wbihua.metrics.metric.PrometheusMetricHistogram;
import com.wbihua.metrics.metric.PrometheusMetricSummary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;


@Component
public class RegistryMetricCounter {
    @Autowired
    private MetricManager metricManager;

    @PostConstruct
    public void registryMetricCounter(){
        //Counter例子
        this.metricManager.registryEventMeterCounter(new EventCounter(EventCounterType.REQUEST_TOTAL));
        this.metricManager.registryEventMeterCounter(new EventCounter(EventCounterType.TAG_REQUEST_TOTAL, metricManager));
        this.metricManager.registryEventMeterCounter(new PrometheusMetricCounter(EventCounterType.PROMETHEUS_REQUEST_TOTAL));
        //Gauge例子
        this.metricManager.registryEventMeterGauge(new EventGauge(EventGaugeType.INPROGRESS_REQUESTS));
        this.metricManager.registryEventMeterGauge(new EventGauge(EventGaugeType.TAG_INPROGRESS_REQUESTS, metricManager));
        this.metricManager.registryEventMeterGauge(new PrometheusMetricGauge(EventGaugeType.PROMETHEUS_INPROGRESS_REQUESTS));

        this.metricManager.registryEventMeterTimer(new EventTimer(EventTimerType.REQUEST_TIMER, metricManager));
        this.metricManager.registryEventMeterSummary(new EventSummary(EventSummaryType.REQUEST_STATUS_SUMMARY, metricManager));

        this.metricManager.registryEventMeterPrometheusHistogram(new PrometheusMetricHistogram(EventPrometheusHistogramType.PROMETHEUS_REQUEST_HISTOGRAM));
        this.metricManager.registryEventMeterPrometheusSummary(new PrometheusMetricSummary(EventPrometheusSummaryType.PROMETHEUS_REQUEST_SUMMARY));
    }
}
